package cn.christ.com.mobilesafe.view.activity_main;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.christ.com.mobilesafe.R;
import cn.christ.com.mobilesafe.common.Global;

/**
 * Created by Administrator on 2018/7/20.
 */

public class MainAdapter extends BaseAdapter {

    private final int[] imgresid;
    private final int[] titles;
    private final int[] des;


    public MainAdapter(int[] imgresid, int[] titles, int[] des) {
        this.imgresid = imgresid;
        this.titles = titles;
        this.des = des;
    }


    @Override
    public int getCount() {
        return imgresid.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = Global.inflate(R.layout.view_lv_main_item);
            viewHolder = new ViewHolder(convertView);
            ButterKnife.bind(this, convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.ivItemType.setImageResource(imgresid[position]);
        viewHolder.tvItemDes.setText(des[position]);
        viewHolder.tvItemTitle.setText(titles[position]);
        return convertView;
    }

    public class ViewHolder {
        @BindView(R.id.iv_item_type)
        ImageView ivItemType;
        @BindView(R.id.tv_item_title)
        TextView tvItemTitle;
        @BindView(R.id.tv_item_des)
        TextView tvItemDes;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
